﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TestPlatform.Core;

namespace TestPlatform.Core
{
    public abstract class BaseUpdatePerformer : ITestPerformer
    {
        private IDatabaseHelper helper;
        private int instanceSize;
        private List<Guid> ids = new List<Guid>();

        public string OperationType { get { return "Update"; } }
        public abstract string UnderlyinEngine { get; }

        public BaseUpdatePerformer(IDatabaseHelper helper)
        {
            this.helper = helper;
        }

        public virtual void Initialize(int instanceSize)
        {
            this.instanceSize = instanceSize;

            ids = helper.SeedDatabase(TestConfig.SeedEntitiesCount);
        }

        public virtual void PerformTest()
        {
            for (int i = 0; i < instanceSize; i++)
            {
                UpdateEntity(ids.RandomElement());
            }
        }

        protected abstract void UpdateEntity(Guid id);

        public virtual void Cleanup()
        {
            ids.Clear();
            helper.ClearDatabase();
        }
    }
}
